package org.zoomdev.zoom.dao.adapters.statement;

import org.zoomdev.zoom.dao.adapters.DataAdapter;
import org.zoomdev.zoom.dao.adapters.StatementAdapter;

import java.sql.PreparedStatement;
import java.sql.SQLException;

public class WrappedStatementAdapter implements StatementAdapter {


    final DataAdapter dataAdapter;
    final StatementAdapter statementAdapter;

    public WrappedStatementAdapter(DataAdapter dataAdapter, StatementAdapter statementAdapter) {
        this.dataAdapter = dataAdapter;
        this.statementAdapter = statementAdapter;
    }

    @Override
    public void adapt(PreparedStatement statement, int index, Object value) throws SQLException {
        //先转化格式
        value = dataAdapter.toDbValue(value);
        statementAdapter.adapt(statement, index, value);
    }
}
